import { ref } from 'vue'
import { getquery_api } from '@/axios/api/slot_management/slot_query'
import { ElNotification } from 'element-plus';
import { useSlotManagementStore } from '@/store/slot_mangement';
const SlotManagementStore = useSlotManagementStore();

export default function () {

    let cons = ref('')


    async function getquery() {
        SlotManagementStore.querytableData_pinia = []
        try {
            let cons_query = cons.value.trim();
            let flag = 0;
            let result = cons_query.split(/[\s, ,，]+/).map(s => `'${s}'`).join(",");
            if (result.split(",").length > 1) {
                cons_query = result;
                flag = 1;
            }
            let res: any = await getquery_api({ con: cons_query, flag: flag })
            if (res.code === 200) {
                SlotManagementStore.querytableData_pinia = JSON.parse(res.data);
                return 'ok';
            } else {
                ElNotification({
                    title: 'Error',
                    message: res.message,
                    type: 'error',
                })
                return Promise.reject(new Error(res.msg))
            }
        } catch (error: any) {
            ElNotification({
                title: 'Error',
                message: error,
                type: 'error',
            })
            return Promise.reject(new Error(error))
        }
    }

    return {
        cons,
        getquery,
    }
}